package cn.snow.iot.framework.mybatis.core.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.ibatis.type.JdbcType;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * @author: raft
 * @date: 2024/7/11 10:19
 * @description: entity基础父类
 */
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
public class BaseEntity implements Serializable {
    @JsonSerialize(
            using = ToStringSerializer.class
    )
    @TableId(
            value = "id"
    )
    private Long id;
    @JsonSerialize(
            using = ToStringSerializer.class
    )
    @TableField(
            fill = FieldFill.INSERT,
            jdbcType = JdbcType.BIGINT
    )
    private Long createUser;
    @JsonSerialize(
            using = ToStringSerializer.class
    )
    private Long createDept;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(
            fill = FieldFill.INSERT,
            jdbcType = JdbcType.VARCHAR
    )
    private LocalDateTime createTime;
    @JsonSerialize(
            using = ToStringSerializer.class
    )
    @TableField(
            fill = FieldFill.INSERT_UPDATE,
            jdbcType = JdbcType.BIGINT
    )
    private Long updateUser;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(
            fill = FieldFill.INSERT_UPDATE
    )
    private LocalDateTime updateTime;
    private Integer status;
    /**
     * 是否删除
     */
    @TableLogic
    private Boolean deleted;
}
